#region Usings
using BK.Entities;
using Lib.Data.CriteriaRoutine;
using Lib.Data.ORM;
using Lib.Data.ORM.Entity;
using Lib.Data.ORM.EntityManagement;
#endregion

namespace BK.BL
{
	[DataView]
	public class PaymentList : BaseGeneralDataView<PaymentItemEntity>
	{
		#region C'tors
		public PaymentList(BaseOrmDataBase ormDataBase) : base(ormDataBase)
		{
		}
		#endregion

		#region Instance Methods
		public PaymentItemEntity GetLastPaymentItem(IdentifierInt userId)
		{
			PaymentItemEntity[] paymentItemEntities = Load(new Criteria("UserId.Value", Clause.Eq, userId.Value),
			                                               new[] {new SortCriteriaItem(SortDirection.Descending, "DateTime")},
														   1);
			return paymentItemEntities.Length == 1 ? paymentItemEntities[0] : null; 
		}
		#endregion
	}
}